<?php
class Download extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
                $this->load->model('Download_m');                
                $this->load->library("my_layout");
                $this->my_layout->setLayout("layout/manager_l");
        }
	function index()
	{
            $data['title']="ダウンロード";
            $session_data_sm = $this->session->userdata('logged_in_mg');
            $data['id_mg'] = $session_data_sm['id_mg'];
            $this->load->helper(array('form'));
            $this->my_layout->view('download/download_v',$data); 
        }
        function verifydownload()
        {
            $data['title']="ダウンロード";
            $session_data_sm = $this->session->userdata('logged_in_mg');
            $data['id_mg'] = $session_data_sm['id_mg'];
            $filedown=$this->input->post('filedown');
            $name=$this->Download_m->getCSVfromDB($filedown);
            $data['name']=$name;
            foreach ($name as $rows) {
            ////code hieu
                $session_array_download=array('name'=>$rows->name,'link'=>$rows->link);
                $this->session->set_userdata('download_file',$session_array_download);
                //echo $rows->Name;
                
                
               //echo anchor('downfile', 'Download');
                //anchor($uri, $title, $attributes)
                //echo "<br>";         
            }
            $this->my_layout->view('download/downfile_v',$data);
        }
        public function downfile()
	{
            $data['title']="ダウンロード";
            $session_data_sm = $this->session->userdata('logged_in_mg');
            $data['id_mg'] = $session_data_sm['id_mg'];
            $session_download = $this->session->userdata('download_file');
            $test=$session_download['name'];
            $data = file_get_contents("./csv_source/".$test); 
            force_download($test, $data);
	}
	
}